.notes-editor-container {
    flex: 1;
    padding: var(--spacing-6);
    padding-top: 0;
    border-left: 1px solid var(--neutral-100);
    transition-property: opacity, transform;
    transition-duration: 300ms;
    transition-timing-function: ease-in-out;
    opacity: 1;
    transform: translateY(0);
    overflow-y: auto;
    word-wrap: break-word;
    max-height: 100%;
    -webkit-overflow-scrolling: touch;

    &::-webkit-scrollbar {
        display: none;
    }

    &.is-hidden {
        opacity: 0;
        padding: 0;
        transform: translateY(10px);
    }

    &.is-expanded {
        position: absolute;
        background: var(--bg-primary);
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: var(--z-base);

        /* Don't take up full width */
        .notes-editor {
            width: var(--notes-editor-max-width);
            margin: 0 auto;
        }
    }

    .notes-editor-toolbar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-top: 18px;
        padding-bottom: 18px;
        position: sticky;
        width: 100%;
        top: 0;
        background: var(--bg-primary);
        z-index: var(--z-base);

        .right-toolbar,
        .left-toolbar {
            display: flex;
            flex-direction: row-reverse;
        }

        .left-toolbar {
            margin-left: -12px;
        }

        svg.lucide {
            cursor: pointer;
            width: 20px;
            height: 20px;
            margin-right: 0;
            transition-property: stroke;
            transition-duration: var(--transition-normal);

            &:hover {

                rect,
                path {
                    stroke: var(--neutral-900);
                }
            }

            &.notes-editor-toolbar-button-hide {
                width: 24px;
                height: 24px;
            }
        }
    }
}

@media screen and (max-width: 948px) {

    .notes-editor-container {
        &.is-visible {
            width: 100%;
            padding: var(--spacing-4);
            padding-top: 0;
            height: calc(100% - (var(--mobile-navbar-height) + var(--safe-area-bottom)));
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: calc(var(--mobile-navbar-height) + var(--safe-area-bottom));
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }

        &.is-hidden {
            display: none;
        }
    }
}

.notes-editor {
    outline: none;

    &.is-editable {
        .notes-editor-image-dropzone {
            display: block;
            border: 1px dashed var(--neutral-300);
            padding: var(--spacing-4);
            margin: var(--spacing-2) 0;
            border-radius: 4px;
            text-align: left;
            font-weight: 500;
            color: var(--neutral-400);
            font-size: 14px;
            cursor: pointer;
            transition-property: background-color, border-color;
            transition-duration: var(--transition-normal);

            &:hover {
                background-color: var(--neutral-50);
                border-color: var(--neutral-400);
            }

            &.dragover {
                background-color: var(--neutral-50);
            }
        }

        .notes-editor-image-attachment-preview {
            display: flex;
            overflow-x: auto;

            img {
                max-height: 200px;
                box-shadow: var(--shadow-2);
                box-sizing: border-box;
                object-fit: cover;
                margin: 16px 16px 16px 0;
                border-radius: 4px;
            }

            &::-webkit-scrollbar {
                display: none;
            }
        }

        .notes-editor-textarea {
            display: block;
            border: 1px solid var(--neutral-200);
            background-color: var(--bg-primary);
            color: var(--text-primary);
            padding: var(--spacing-4);
            border-radius: 4px;
        }

        .notes-editor-rendered {
            display: none;
        }

        .notes-editor-empty-text {
            display: none;
        }
    }

    .notes-editor-empty-text {
        font: var(--sm);
        padding: var(--spacing-4);
        color: var(--neutral-400);
        display: flex;
        justify-content: center;
        align-items: center;
        margin-top: 64px;
    }
}

.notes-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-8);
}

.notes-editor-title {
    font: var(--h1);

    &[contenteditable="true"] {
        outline: none;
        border-bottom: 1px solid var(--neutral-200);
        padding-bottom: 4px;
        width: 100%;
        margin-right: var(--spacing-4);
    }
}

.notes-editor-tags {
    margin-bottom: var(--spacing-4);
}

.notes-editor-tags-input {
    padding: 2px var(--spacing-2);
    outline: none;
    font-weight: 500;
    color: var(--neutral-400);
    font-size: 14px;
    border: 1px dashed var(--neutral-300);
    background-color: var(--bg-primary);
    border-radius: 4px;
    width: 100px;
}

.notes-editor-image-dropzone,
.notes-editor-image-attachment-preview {
    display: none;
}

.notes-editor-textarea {
    font-family: var(--font-family-code);
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    padding-right: 10px;
    display: none;
}

.notes-grid-item-content,
.notes-editor-rendered {
    display: block;
    overflow-x: auto;

    strong {
        font-weight: 600;
    }

    em {
        font-style: italic;
    }

    h1 {
        font: var(--h2);
        margin-bottom: 24px;
    }

    h2 {
        font: var(--h3);
    }

    h3 {
        font: var(--h5);
    }

    h4,
    h5,
    h6 {
        font: var(--h6);
    }

    p,
    blockquote,
    ul,
    ol,
    li,
    table {
        font: var(--p1);
        padding: 3px 0;
    }

    a {
        color: var(--neutral-500);
        text-decoration: none;
        border-bottom: 1px dashed var(--neutral-500);
    }

    img {
        width: auto;
        max-width: 100%;
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        padding: 3px 0;
        margin-top: 24px;
        margin-bottom: 4px;
        font-weight: 600;
    }

    code {
        font: var(--code);
        background-color: var(--neutral-50);
        border-radius: 4px;
        padding: var(--spacing-1) var(--spacing-2);
    }

    pre {
        margin: 4px 0;
        padding: var(--spacing-3);
        background-color: var(--neutral-50);
        border-radius: 4px;
        overflow: scroll;

        &::-webkit-scrollbar {
            display: none;
        }

        code {
            background-color: unset;
            border-radius: 0;
            padding: 0;
        }

        * {
            font: var(--code);
        }
    }

    blockquote {
        border-left: 3px solid var(--neutral-700);
        padding-left: 10px;
        margin: 10px 4px;
    }

    ul {
        padding-left: 20px;
    }

    ol {
        padding-left: 30px;
    }

    ul>li>ul,
    ol>li>ul {
        padding-top: 0;
        padding-bottom: 0;
    }

    li>ul>li,
    li>ol>li {
        padding-bottom: 0;
    }

    .task-list-container {
        list-style: none;
        padding: 0;
        margin: 0;
    }

    .task-list-item {
        padding-left: 0;
    }

    .task-list-item:has(> .task-list-container) {
        margin-bottom: 0;
        padding-bottom: 0;
    }

    .task-item-content {
        display: flex;
        align-items: center;
        gap: var(--spacing-2);
    }

    .task-list-item-checkbox {
        flex-shrink: 0;
        cursor: pointer;
        color: var(--neutral-400);
        transition: color 0.2s ease;

        &:hover {
            color: var(--neutral-600);
            cursor: not-allowed;
        }

        &.checked {
            color: var(--neutral-700);

            &:hover {
                color: var(--neutral-600);
            }
        }
    }

    .task-list-item>.task-list-container {
        padding-left: 24px;
        margin-bottom: 0;
    }

    table {
        width: 100%;
        border-collapse: collapse;
        margin: 24px 0;
    }

    table,
    th,
    td {
        border: 1px solid var(--neutral-200);
        padding: 5px 15px;
        width: max-content;
    }

    th {
        text-align: left;
    }

    hr {
        margin-top: 24px;
        margin-bottom: 24px;
        border: 1px solid var(--neutral-100);
    }

    s {
        color: var(--neutral-400);
    }

    mark {
        background: rgba(250, 204, 21, 0.1);
        color: var(--yellow-500);
        border-radius: 4px;
        padding: 2px;
    }
}

.formatting-toolbar {
    display: none;
    flex-wrap: wrap;
    gap: var(--spacing-2);
    margin: var(--spacing-3) 0;
    border: 1px solid var(--neutral-300);
    border-radius: 4px;
    align-items: center;

    .notes-editor.is-editable & {
        display: flex;
    }

    .formatting-toolbar-group {
        display: flex;
        padding-right: var(--spacing-2);

        &:last-child {
            border-right: none;
            padding-right: 0;
        }

        .formatting-button {
            background: none;
            border: none;
            border-radius: 4px;
            padding: 6px var(--spacing-2);
            cursor: pointer;
            font-size: 12px;
            font-weight: 500;
            color: var(--text-primary);
            transition: all 0.2s ease;
            min-width: 32px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            white-space: nowrap;
            margin: 4px;

            &:hover {
                background-color: var(--neutral-200);
            }

            &:active {
                background-color: var(--neutral-100);
                transform: translateY(0);
                box-shadow: none;
            }

            svg.lucide {
                width: 16px;
                height: 16px;
                stroke: currentColor;
            }

            strong,
            em,
            s,
            mark,
            code {
                font-size: 12px;
                font-weight: 600;
                margin: 0;
                padding: 0;
            }

            mark {
                background: var(--yellow-200);
                border-radius: 2px;
                padding: 1px 2px;
            }

            code {
                background: var(--neutral-100);
                border-radius: 2px;
                padding: 1px 2px;
                font-family: var(--font-family-code);
            }
        }
    }
}

@media screen and (max-width: 948px) {
    .formatting-toolbar {
        display: none;

        .notes-editor.is-editable & {
            display: none;
        }
    }
}